package testGroovy

import java.text.SimpleDateFormat
import java.time.ZonedDateTime

import static java.time.ZoneId.systemDefault
import static java.time.ZonedDateTime.now
import static java.time.ZonedDateTime.ofInstant as date

/**
 * Created by houjinxin on 15/9/23.
 */

def  _DATE_FORMAT3 = new SimpleDateFormat('yyyy-MM-dd')
def date1 = date(_DATE_FORMAT3.parse('2015-08-12').toInstant(), systemDefault())
def date2 = date(_DATE_FORMAT3.parse('2015-10-12').toInstant(), systemDefault())

def localDate1 = date1.toLocalDate()
def localDate2 = date2.toLocalDate()
println date1 < date2
println localDate1 < localDate2

//System.getenv().each { key, value ->
//    println key + ':' + value
//}
//println System.getenv('GRADLE_HOME')

//System.getProperties().entrySet().each { entry ->
//    println entry.key + '=' + entry.value
//}

def getCommercialEarliestDate(errorMsg) {
    def m = errorMsg =~ /.*>(\d{4})-(\d{2})-(\d{2})<.*/
    m.matches() ? date(new SimpleDateFormat('yyyy-MM-dd').parse("${m[0][1]}-${m[0][2]}-${m[0][3]}").toInstant(), systemDefault()) : now()
}

def errorMsg = '根据当地监管政策，您的车离交强险可投保还有281天，但您现在还可以先投保商业险。'
def result1 = errorMsg =~  /.*还有(\d{1,3})天.*/
println 'pipei='+result1.matches()
println result1[0][1]
//println ZonedDateTime.now().plusDays(0).toLocalDate()

def errorMsg1 = "抱歉，您的商业险还有很久才到期呢，您可以：<br>1．直接点下一步继续投保交强险，商业险请在[<span style='color:#f00;'>2016-08-12</span>]后再来投保。<br>2．或者核对保险生效日期，若不正确请修改。"
println getCommercialEarliestDate(errorMsg1).toLocalDate()


